package com.gitee.dolt.core.validator;

import com.gitee.dolt.base.validation.IRemoteValidator;
import com.gitee.dolt.core.util.SpringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author LYH
 */
public class RemoteConstraintValidator implements ConstraintValidator<Remote, Object> {

    private IRemoteValidator customValidator;
    private String param;

    @Override
    public void initialize(Remote constraintAnnotation) {
        this.customValidator = SpringUtils.getBean(constraintAnnotation.bean(), IRemoteValidator.class);
        this.param = constraintAnnotation.param();
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        return customValidator.valid(value, this.param);
    }

}